<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="file" name="file" id="upload" onchange="handleFiles(this.files)">
    <input type="button" name="" id="submit" value="submit">
    <input type="button" name="" id="pull" value="pull">
    <script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
    <script>
        var upload = document.querySelector("#upload");
        var submit = document.querySelector("#submit");
        var pull= document.querySelector("#pull");
        var netsite = "http://39.103.159.52:6607";
        var workbook
        function handleFiles(files) {
            if (files.length) {
                let file = files[0];
                let reader = new FileReader();
                console.log(1);
                reader.onload = function () {
                    console.log(1);
                    workbook = XLSX.read(this.result, { type: 'binary' });
                    console.log(workbook);
                    workbook=JSON.stringify(workbook);
                    console.log(workbook);
                };
                reader.readAsBinaryString(file)
            }
        }

        submit.addEventListener("click", () => {
            const xhr = new XMLHttpRequest();
            xhr.open('POST', netsite + '/upload');
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send(workbook);
            xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status < 300) {
                    alert(xhr.response);
                }
            }
            return false;
        }
        })

        pull.addEventListener("click",()=>{
            window.location =netsite+"/files/result.xlsx"
        })


    </script>
</body>

</html>